﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETDBTableAdapters;

public partial class Administration_files_Upload : System.Web.UI.Page
{
    FilesTableAdapter fTable = new FilesTableAdapter();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            FileUploadStatus.Text = "";
    }

    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile)
        {
            try
            {
                string filename = System.IO.Path.GetFileName(FileUploadControl.FileName);
                FileUploadControl.SaveAs(Server.MapPath("~/Files/") + filename); //Change the server pathway for uploading images

                FilesTableAdapter contentAdapter = new FilesTableAdapter();

                String description = FileUploadDescription.Text;
                if (description == null)
                    description = "";
                fTable.InsertFile(filename, description);
                Response.Redirect("index.aspx");
            }
            catch (Exception ex)
            {
                FileUploadStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }
}